<!--
 * @name: 圈子列表
 * @version: 1.1.1
 * @Author: 刘大可
 * @Date: 2022-07-19 10:51:57
 * @LastEditors: 刘大可
 * @LastEditTime: 2023-11-08 15:31:32
-->
<template>
    <view class="margin">

        <!-- {{ JSON.stringify(authData)}} -->

        <view class="tab_bar flex">
            <view class="tab" :class="type == 0?'cur':''" @tap="changetype" data-type="0">全部</view>
            <view class="tab" :class="type == 2?'cur':''" @tap="changetype" data-type="2">最新</view>
            <view class="tab" :class="type == 1 ? 'cur' : ''" @tap="changetype" data-type="1">最热</view>
        </view>
        <!-- 分类 -->
        <view class="cate_box flex margin-top justify-between" v-if="1 == 2">
            <view class="cate_item_box flex">
                <block key="index" v-for="(item, index) in cateList" :key="index">
                    <view @tap="cateChange" :data-index="index"
                        :class="'cate_item ' + (cate_index == index ? 'cate_active' : '')">{{ item.class_name }}</view>
                </block>
            </view>
            <view class="flex label_box" v-if="cateList.length > 0">
                <view @tap="changetype" data-type="2" :class="'label_item ' + (type == 2 ? 'label_item_active' : '')">最新
                </view>
                <view @tap="changetype" data-type="1" :class="'label_item ' + (type == 1 ? 'label_item_active' : '')">最热
                </view>
            </view>
        </view>

        <!-- 文章列表 -->
        <view class="padding-bottom" style="padding-bottom: 100rpx">
            <block v-if="dataList.length == 0">
                <view class="text-center margin-top text-df">暂无数据~</view>
            </block>
            <block v-for="(item, index) in dataList" :key="index">
                <!-- <view class="article padding"  @click="toDetail(item.article_id)" :data-id="item.article_id"> -->
                <view class="article padding"  :class="{isNoAuth:(item.is_auth_watch==1&&authData.status==0)}"  @click="toList(2, item.article_id, item.is_auth)"
                    :data-id="item.article_id">
                    <view class="flex row">
                        <image v-if="item.is_anonymous == 0" class="avatar"
                            :src="item.avatar ? item.avatar : ( fileUrl+'avatar.jpg')"
                            mode="scaleToFill" />
                        <image v-else class="avatar" :src=" fileUrl+'avatar.jpg'"
                            mode="scaleToFill" />
                            
                        <view class="nickname" >{{ item.is_anonymous == 1 ? "匿名用户" : item.nickname }}</view>
                        <view class="date">{{ item.createtime }}</view>
                        <image class="top" src="/static/icon/top.png" v-if="item.is_expired == 1" />
                    </view>
                    <view class="content margin-tb" v-for="(ditems, dindexs) in item.topic" :key="dindexs"
                        v-if="ditems">
                        <view class="topic-title"># {{ ditems.title }}</view>
                    </view>
                    <view class="content margin-tb">
                        <!-- {{item.content}} -->
                        <!-- <rich-text :nodes="item.content"></rich-text> -->
                        <text space="nbsp" class="line_two" style=" -webkit-line-clamp: 3;;word-break: break-word;"
                            :decode="true">{{ item.content }}</text>

                    </view>
                    <view class="imgs row  margin-bottom" v-if="item.image.length > 0">
                        <block v-for="(image, index) in item.image" :key="index">
                            <image class="img" :src="image" mode="aspectFill" />
                        </block>
                    </view>
                    <view v-if="item.video" @click.stop="">
                        <video :src="item.video" style="width: 100%;" class="margin-bottom"></video>
                    </view>
                    <view class="footer row">
                        <view class="class_name" v-if="item.class_name">
                            {{ item.class_name }}
                        </view>
                        <view class="view" style="margin-top:0px;">
                            <image style="height: 45rpx;" class="icon" src="/static/icon/views.png"
                                mode="scaleToFill" />
                            {{ item.views_num }}
                        </view>
                        <view class="comment">
                            <image class="icon" src="/static/icon/comment.png" mode="scaleToFill" />
                            {{ item.comments_num }}
                        </view>
                        <view class="love" :class="item.is_fav == 1 ? 'cur' : ''">
                            <image class="icon" src="/static/icon/love.png" mode="scaleToFill" />
                            {{ item.likes_num }}
                        </view>
                    </view>

                </view>
            </block>
            <block key="index" v-for="(item, index) in dataList" :key="index" v-if="1 == 2">
                <view class="article_box padding" @tap="toDetail" :data-id="item.article_id">
                    <view class="flex">
                        <block v-if="item.is_anonymous == 0">
                            <image class="avatar"
                                :src="item.avatar ? item.avatar : 'https://gcwe7.link1024.com/web/img/avatar.png'">
                            </image>
                            <view class="">
                                <view class="nickname">{{ item.nickname }}</view>
                                <view class="date">{{ item.createtime }}</view>
                            </view>
                        </block>
                        <block v-else>
                            <image class="avatar" src="https://gcwe7.link1024.com/web/img/avatar.png"></image>
                            <view class="">
                                <view class="nickname">匿名用户</view>
                                <view class="date">{{ item.createtime }}</view>
                            </view>
                        </block>
                    </view>
                    <view class="content margin-top">{{ item.content }}</view>
                    <view v-if="item.media_type == '1'" class="margin-top">
                        <video @tap.stop.prevent="play" style="width: 100%" :src="item.video"></video>
                    </view>
                    <view v-else-if="item.media_type == '2'" class="margin-top">
                        <block v-for="(img, index1) in item.image" :key="index1">
                            <image mode="aspectFill" @tap.stop.prevent="preview" :data-img="img" :data-list="item.image"
                                class="item_img" :src="img"></image>
                        </block>
                    </view>
                    <view class="flex justify-between margin-top">
                        <view class="flex icon_item">
                            <image src="/static/images/article/share.png"></image>
                            <text>{{ item.collections_num }}</text>
                        </view>
                        <view class="flex icon_item">
                            <image src="/static/images/article/comment.png"></image>
                            <text>{{ item.comments_num }}</text>
                        </view>
                        <view class="flex icon_item">
                            <image src="/static/images/article/fav.png"></image>
                            <text>{{ item.likes_num }}</text>
                        </view>
                    </view>
                </view>
            </block>
        </view>
    </view>
</template>
<script>
var app = getApp();

export default {
    data() {
        return {
            dataList:[],
            type: 0,
            is_loadmore: true,
            page: 1,
          
            authData: { status: 0 },
        }
    },
    created() {
        this.getLst()
        if (uni.getStorageSync('token')) {
            this.getAuth()
        }
    },
    methods: {
        changetype(e) {
            this.setData({
                type: e.currentTarget.dataset.type,
                page: 1,
                is_loadmore: true,
                dataList: []
            });
            this.getLst();
        },
        getLst(cid) {
            var that = this;
            app.globalData.util.request({
                url: 'ZhArticles/index',
                method: 'GET',
                data: {
                    s_id: uni.getStorageSync('schoolId'),
                    // class_id: cid,
                    type: that.type,
                    page: that.page
                },
                header: {
                    'Authorization': uni.getStorageSync('token')
                },
                success(res) {
                    console.log(res.data.data.list);

                    if (res.data.data.list.length < 5) {
                        that.setData({
                            is_loadmore: false
                        });
                    }

                    for (var i = 0; i < res.data.data.list.length; i++) {
                        that.dataList.push(res.data.data.list[i]);
                        that.setData({
                            dataList: that.dataList
                        });
                    }
                }
            });
        },

        toList(type, id, auth, url, name) {
            if (type == 1) {
                var urls = '/gc_school/pages/article/list?class_id=' + id + '&class_name=' + name
            }
            else {
                var urls = '/gc_school/pages/article/detail?id=' + id
            }
            console.log(name)
            if (url) {
                uni.navigateTo({
                    url: url
                })
            }
            else {
                if (auth == 0) {
                    uni.navigateTo({
                        url: urls
                    })
                }
                //需要认证的分类
                else {
                    //没有认证过，提示去认证
                    if (this.authData.status == 0) {
                        uni.showModal({
                            title: '温馨提示',
                            content: '本内容只对本校认证学生查看，请先认证！',
                            success(res) {
                                if (res.confirm) {
                                    uni.navigateTo({
                                        url: '/gc_school/pages/user/student'
                                    })
                                } else {
                                    console.log('取消删除');
                                }
                            }
                        });
                    }
                    else {
                        //判断是否和当前一个学校
                        if (this.authData.data.s_id != uni.getStorageSync('schoolId')) {
                            uni.showToast({
                                title: '您好，本内容只对本校认证学生查看，您暂无权限。',
                                icon: 'none',
                                duration: 3000
                            })
                        }
                        else {
                            if (this.authData.data.state == 0) {
                                uni.showToast({
                                    title: '请等待审核结果',
                                    icon: 'none',
                                    duration: 3000
                                })
                            } else if (this.authData.data.state == 2) {
                                uni.navigateTo({
                                    url: '/gc_school/pages/user/student'
                                })
                            } else {
                                uni.navigateTo({
                                    url: urls
                                })
                            }
                        }
                    }
                }
            }

        },

        getAuth() {
            var that = this;
            app.globalData.util.request({
                url: 'RenIndex/student',
                method: 'POST',
                data: {},
                success(res) {
                    that.authData = res.data.data
                    // if(res.data.data.msg == '您的账号已被禁用，请联系客服。'){
                    // 	uni.setStorageSync('userstate', '-1');
                    // }else{
                    // 	uni.setStorageSync('userstate', '1');
                    // }
                    // that.setData({
                    //     slideList: res.data.data.list
                    // });
                }
            }, true);
        },

    },
}
</script>

<style lang="scss">
    @import "./main.scss";
</style>